package demo;

import java.util.*;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.*;
import javafx.scene.input.MouseButton;
import javafx.scene.shape.*;
import javafx.scene.paint.Color;

// 鼠标画圆(可延伸)     
public class PicturePainter extends Application { 
	private Pane root = new Pane();
	private Circle circle;
	private ArrayList<Shape> list = new ArrayList<>();
	
	public static void main(String[] args) {
		Application.launch(args);
	}
	
	@Override
	public void start(Stage a) {
		
		Scene cc = new Scene(root, 400, 300);
		a.setScene(cc);
		a.show();
		
		// 事件
		// 鼠标控制画点
		root.setOnMouseClicked(e -> {
			if(e.getButton() == MouseButton.PRIMARY) {         	// 左键
				circle = new Circle(e.getX(), e.getY(), 10, Color.ORANGE);
				root.getChildren().add(circle);
				list.add(circle);
				
			} else if(e.getButton() == MouseButton.SECONDARY) {    // 右键
				for(int i=0; i<list.size(); i++) {
					if(list.get(i).contains(e.getX(), e.getY())) {
						root.getChildren().remove(i);
						list.remove(i);
					}
				}
			}
		});
	}
}




